<template>
  <a-form
    :model="formState"
    ref="formDataRef"
    name="basic"
    :label-col="{ style: 'width:80px' }"
    :wrapper-col="{ style: 'calc(100% - 80px)' }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="发票模板" name="bizExportTemplateId" :rules="[{ required: true, message: '请选择发票模板!' }]">
      <a-select v-model:value="formState.bizExportTemplateId" placeholder="请选择">
        <a-select-option v-for="(item, index) in invoiceTemplateOpts" :key="index" :value="item.id">{{ item.name }}</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
      <a-button :loading="loading" type="primary" html-type="submit">确定</a-button>
      <a-button @click="resetHandle">取消</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts" setup>
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import { toRefs, watch } from "vue";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: Array<BusinessWaybill.ListRows>;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", blo: boolean): void;
  (e: "submit"): void;
}>();
const { visible, passData } = toRefs(props);
const { formDataRef, formState, invoiceTemplateOpts, getAllInvoiceTemplate, loading } = InitHook();
const { onFinish, onFinishFailed, resetHandle } = OperationHook({ loading, formState, formDataRef, emit, passData });
getAllInvoiceTemplate();
watch(
  () => visible.value,
  (v: boolean) => {
    if (v) {
      console.log(passData.value);
      getAllInvoiceTemplate();
    }
  }
);
</script>
<style lang="stylus" scoped></style>
